package com.atelier.plugin.database.action;

import com.atelier.plugin.database.ui.DataBaseToolWindowContent;
import com.atelier.plugin.database.util.TreeUtil;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.util.NlsActions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.sql.SQLException;
import java.util.function.Supplier;

/**
 * Expand All Ctrl+NumPad +
 */
public class MyCollapseAllAnAction extends DumbAwareAction {

    public MyCollapseAllAnAction() {
        super("<html>" + "Collapse All" + "  " + "<font  color='8A8E9A'>" + " Ctrl+NumPad +" + "</font></html>",
                "Ctrl+NumPad -", AllIcons.Actions.Collapseall);
    }

    /**
     * @param e Carries information on the invocation place
     */

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        try {
            JTree databaseTree = DataBaseToolWindowContent.getInstants().getDatabaseTree();
            TreeUtil.collapseAll(databaseTree);
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }

    }

}
